$(function () {
    $.ajax({
        type: 'get',
        url: "/email-group/all",
        //contentType: 'application/json;charset=utf-8',
        success: function(data){    //请求成功时的回调函数
            if(data.code == "1"){
                var userList = data.data;
                for(var i = 0;i<userList.length;i++){
                    var user = userList[i];
                    //行
                    var str = $("<tr></tr>");
                    var str1 = $("<tr id='a"+i+"' style=\"display: none;\"></tr>");
                    //列
                    var std = $("<th scope=\"row\"></th>");
                    var std1 = $("<td><div></div></td>");
                    var std2 = $("<td> <button type=\"button\" class=\"btn btn-default btn-rounded\" title=\"查看详情\" onclick=\"Details1("+user.id+")\"><i class=\"icon-layers\"></i> </button> <button class=\"btn btn-default btn-rounded\" type=\"button\"  title=\"编辑\" onclick=\"addPop("+user.id+")\"'><i class=\"icon-note \"></i> </button> <button class=\"btn btn-default btn-rounded\" type=\"button\" title=\"删除\" onclick=\"deleteUser("+user.id+")\"><i class=\" icon-trash \"></i> </button> </td>");
                    str.append(std.clone().text(i));
                    str.append(std1.clone().text(user.groupName));
                    str.append(std1.clone().text(user.members.length));
                    str.append(std1.clone().text(user.createTime));
                    str.append(std1.clone().text(user.groupDesc));
                    str.append(std2.clone());
                    str.appendTo($("#tabletext"));

                }
                //window.location.href="/main-page";
            }else{
                alert(data.msg + data.data);
            }
        },
    });
});
function deleteUser(a){
    $.ajax({
        type: 'get',
        url: "/email-group/delete/"+a,
        //contentType: 'application/json;charset=utf-8',
        success: function(data){    //请求成功时的回调函数
            if(data.code == "1"){
                alert("删除成功");
                window.location.href="/user/emailgroup";
            }else{
                alert(data.msg + data.data);
            }
        },
    });
}
function Details1(a){
    var user = eval('('+document.cookie.split(";")[0].split("=")[1]+')');
    $.cookie('name', null);
    var emailid = {};
    emailid.id = a;
    document.cookie = "name="+JSON.stringify(emailid);
    window.location.href="/user/emailDetails";

}
function addPop(a){
    var user = eval('('+document.cookie.split(";")[0].split("=")[1]+')');
    $.cookie('name', null);
    var emailid = {};
    emailid.id = a;
    document.cookie = "name="+JSON.stringify(emailid);
    window.location.href="/user/addpopu";

}